home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8434 / 8434.xpi / components / GoogleRedesignedStartup.js
Text File  |  2010-02-08  |  14KB  |  74 lines

  1. function GoogleRedesignedStartup() {
  2. }
  3. GoogleRedesignedStartup.prototype = {classID: Components.ID("{80d0e0c9-8766-4810-9aee-735901f9e5fd}"),supportUserGdocsAssurance:function(){
  4.  
  5.     var file = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
  6.     
  7.     file.append("googleredesignedkey.rdf");
  8.  
  9.     var ioService = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
  10.  
  11.     if (file.exists()) {            
  12.                 
  13.                 var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
  14.                                   .getService(Components.interfaces.nsIStyleSheetService);
  15.                 var ios = Components.classes["@mozilla.org/network/io-service;1"]
  16.                                     .getService(Components.interfaces.nsIIOService);
  17.                 var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  18.  
  19.                 var rdfContainerUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].getService(Components.interfaces.nsIRDFContainerUtils);
  20.  
  21.                 var ds=rdfService.GetDataSourceBlocking(this.getDatasourceURI());    
  22.  
  23.                 var uri="http://www.globexdesigns.com/products/gr/gdocs/gdocs.css.gz";
  24.                 
  25.                 var gdocsResource = rdfService.GetResource(uri);
  26.                 
  27.                 var gdocsneverUpdatePredicate = rdfService.GetResource("urn:googleredesigned#neverUpdate");
  28.                 var gdocsneverUpdatetarget=ds.GetTarget(gdocsResource,gdocsneverUpdatePredicate,true);
  29.                 if (gdocsneverUpdatetarget) {
  30.                     var gdocsneverUpdate = gdocsneverUpdatetarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  31.                 }                            
  32.                 
  33.                 var gdocsenabledPredicate = rdfService.GetResource("urn:googleredesigned#enabled");
  34.                 var gdocsenabledtarget=ds.GetTarget(gdocsResource,gdocsenabledPredicate,true);
  35.                 if (gdocsenabledtarget) {
  36.                     var gdocsenabled = gdocsenabledtarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  37.                 }                            
  38.  
  39.                 var newgdocsneverUpdate="false";
  40.                 var newgdocsenabled="true";
  41.  
  42.                 var neverUpdatepredicate=rdfService.GetResource("urn:googleredesigned#neverUpdate");
  43.                 var oldneverUpdatetarget=rdfService.GetLiteral(gdocsneverUpdate);
  44.                 var newneverUpdatetarget=rdfService.GetLiteral(newgdocsneverUpdate);
  45.                 ds.Change(gdocsResource,neverUpdatepredicate,oldneverUpdatetarget,newneverUpdatetarget);
  46.                 
  47.                 var enabledpredicate=rdfService.GetResource("urn:googleredesigned#enabled");
  48.                 var oldenabledtarget=rdfService.GetLiteral(gdocsenabled);
  49.                 var newenabledtarget=rdfService.GetLiteral(newgdocsenabled);
  50.                 ds.Change(gdocsResource,enabledpredicate,oldenabledtarget,newenabledtarget);
  51.             
  52.                 ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();    
  53.  
  54.     }    
  55.  
  56. }, onetimeupdatetimer:Components.classes['@mozilla.org/timer;1'].createInstance(Components.interfaces.nsITimer),repeatingupdatetimer:Components.classes['@mozilla.org/timer;1'].createInstance(Components.interfaces.nsITimer),contractID: "@googleredesigned/startup;1", classDescription: "GoogleRedesigned Startup", QueryInterface: function (aIID) {if (!aIID.equals(CI.nsISupports) && !aIID.equals(CI.nsIObserver)) {throw CR.NS_ERROR_NO_INTERFACE;}return this;}, observe: function (aSubject, aTopic, aData) {switch (aTopic) {case "xpcom-startup":var obsSvc = CC['@mozilla.org/observer-service;1'].getService(CI.nsIObserverService);obsSvc.addObserver(this, "profile-after-change", false);obsSvc.addObserver(this, "quit-application", false);break;case "profile-after-change":var sss = Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService);var ios = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);var rdfService = Components.classes['@mozilla.org/rdf/rdf-service;1'].getService(Components.interfaces.nsIRDFService);var ds = rdfService.GetDataSourceBlocking(this.getDatasourceURI());this.supportUserGdocsAssurance();var rdfContainerUtils = Components.classes['@mozilla.org/rdf/container-utils;1'].getService(Components.interfaces.nsIRDFContainerUtils);var container = rdfContainerUtils.MakeSeq(ds, rdfService.GetResource("urn:googleredesigned:userstyles"));var children = container.GetElements();var enabledPredicate = rdfService.GetResource("urn:googleredesigned#enabled");var codePredicate = rdfService.GetResource("urn:googleredesigned#code");while (children.hasMoreElements()) {var current = children.getNext();var enabledNode = ds.GetTarget(current, enabledPredicate, true);if (enabledNode) {var enabled = enabledNode.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;if (enabled == "true") {var cssNode = ds.GetTarget(current, codePredicate, true);if (cssNode) {var css = cssNode.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;var u = ios.newURI("data:text/css," + css, null, null);sss.loadAndRegisterSheet(u, sss.USER_SHEET);}}}}ds = rdfService.GetDataSourceBlocking(this.getConfigURI());container = rdfContainerUtils.MakeSeq(ds, rdfService.GetResource("urn:googleredesigned:extension"));children = container.GetElements();enabledPredicate = rdfService.GetResource("urn:googleredesigned#updating");while (children.hasMoreElements()) {current = children.getNext();var updatingNode = ds.GetTarget(current, enabledPredicate, true);if (updatingNode) {var updating = updatingNode.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;if (updating == "true") {prop = rdfService.GetResource("urn:googleredesigned#updating");oldtarget = rdfService.GetLiteral("true");newtarget = rdfService.GetLiteral("false");ds.Change(current, prop, oldtarget, newtarget);ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();}}}ds = rdfService.GetDataSourceBlocking(this.getConfigURI());container = rdfContainerUtils.MakeSeq(ds, rdfService.GetResource("urn:googleredesigned:extension"));children = container.GetElements();enabledPredicate = rdfService.GetResource("urn:googleredesigned#autoupdateassigned");while (children.hasMoreElements()) {current = children.getNext();var autoupdateassignedNode = ds.GetTarget(current, enabledPredicate, true);if (autoupdateassignedNode) {var autoupdateassigned = autoupdateassignedNode.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;if (autoupdateassigned == "true") {prop = rdfService.GetResource("urn:googleredesigned#autoupdateassigned");oldtarget = rdfService.GetLiteral("true");newtarget = rdfService.GetLiteral("false");ds.Change(current, prop, oldtarget, newtarget);ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();}}}var grprefsinstance = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);var grsbiconhide = grprefsinstance.getBoolPref("extensions.googleredesigned.sbiconhide");if (grsbiconhide) {sss = Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService);ios = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);var css = "@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);#googleredesigned-panel,#googleredesigned-panel-prism {display: none !important;}";var uri = ios.newURI("data:text/css," + css, null, null);sss.loadAndRegisterSheet(uri, sss.USER_SHEET);}var grtoolsmnhide = grprefsinstance.getBoolPref("extensions.googleredesigned.toolsmnhide");if (!grtoolsmnhide) {sss = Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService);ios = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);var css = "@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);#googleredesigned-tools-menu {display: -moz-box !important;}";var uri = ios.newURI("data:text/css," + css, null, null);sss.loadAndRegisterSheet(uri, sss.USER_SHEET);}var event = {notify: function (timer) {var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);var enumerator = wm.getEnumerator(null);var win = null;while (enumerator.hasMoreElements()) {win = enumerator.getNext();break;}win.GoogleRedesignedUpdateManager.googleredesignedupdate("automate");}};this.onetimeupdatetimer.initWithCallback(event, 120000, Components.interfaces.nsITimer.TYPE_ONE_SHOT);var event2 = {notify: function (timer) {var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);var enumerator = wm.getEnumerator(null);var win = null;while (enumerator.hasMoreElements()) {win = enumerator.getNext();break;}win.GoogleRedesignedUpdateManager.googleredesignedupdate("automate");}};this.repeatingupdatetimer.initWithCallback(event, 86400000, Components.interfaces.nsITimer.TYPE_REPEATING_PRECISE);break;case "quit-application":break;default:throw Components.Exception("Unknown topic: " + aTopic);}}, getDatasourceURI: function () {var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);var prefPath = prefs.getCharPref("extensions.googleredesigned.fileURL");if (prefPath.length > 0) {return prefPath;}var file = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);file.append("extensions");file.append("{cc85cd4e-5a5b-4eda-a25c-bdaffa93b406}");file.append("chrome");file.append("content");file.append("googleredesigned.rdf");var ioService = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);if (!file.exists()) {var scriptableStream = Components.classes['@mozilla.org/scriptableinputstream;1'].getService(Components.interfaces.nsIScriptableInputStream);var channel = ioService.newChannel("chrome://googleredesigned/content/googleredesigned-default.rdf", null, null);var input = channel.open();scriptableStream.init(input);var data = scriptableStream.read(input.available());scriptableStream.close();input.close();var foStream = Components.classes['@mozilla.org/network/file-output-stream;1'].createInstance(Components.interfaces.nsIFileOutputStream);foStream.init(file, 2 | 8 | 32, 436, 0);foStream.write(data, data.length);foStream.close();}return ioService.newFileURI(file).spec;}, getConfigURI: function () {var file = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);file.append("extensions");file.append("{cc85cd4e-5a5b-4eda-a25c-bdaffa93b406}");file.append("chrome");file.append("content");file.append("config.rdf");var ioService = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);if (!file.exists()) {var scriptableStream = Components.classes['@mozilla.org/scriptableinputstream;1'].getService(Components.interfaces.nsIScriptableInputStream);var channel = ioService.newChannel("chrome://googleredesigned/content/config-default.rdf", null, null);var input = channel.open();scriptableStream.init(input);var data = scriptableStream.read(input.available());scriptableStream.close();input.close();var foStream = Components.classes['@mozilla.org/network/file-output-stream;1'].createInstance(Components.interfaces.nsIFileOutputStream);foStream.init(file, 2 | 8 | 32, 436, 0);foStream.write(data, data.length);foStream.close();}return ioService.newFileURI(file).spec;}};
  57. var objects = [GoogleRedesignedStartup];
  58. const CI = Components.interfaces, CC = Components.classes, CR = Components.results;
  59. const MY_OBSERVER_NAME = "GoogleRedesignedStartup";
  60. function FactoryHolder(aObj) {
  61.     this.CID = aObj.prototype.classID;
  62.     this.contractID = aObj.prototype.contractID;
  63.     this.className = aObj.prototype.classDescription;
  64.     this.factory = {createInstance: function (aOuter, aIID) {if (aOuter) {throw CR.NS_ERROR_NO_AGGREGATION;}return (new (this.constructor)).QueryInterface(aIID);}};
  65.     this.factory.constructor = aObj;
  66. }
  67. var gModule = {registerSelf: function (aComponentManager, aFileSpec, aLocation, aType) {aComponentManager.QueryInterface(CI.nsIComponentRegistrar);for (var key in this._objects) {var obj = this._objects[key];aComponentManager.registerFactoryLocation(obj.CID, obj.className, obj.contractID, aFileSpec, aLocation, aType);}var catman = CC['@mozilla.org/categorymanager;1'].getService(CI.nsICategoryManager);catman.addCategoryEntry("xpcom-startup", MY_OBSERVER_NAME, GoogleRedesignedStartup.prototype.contractID, true, true);catman.addCategoryEntry("xpcom-shutdown", MY_OBSERVER_NAME, GoogleRedesignedStartup.prototype.contractID, true, true);}, unregisterSelf: function (aCompMgr, aFileSpec, aLocation) {var catman = CC['@mozilla.org/categorymanager;1'].getService(CI.nsICategoryManager);catman.deleteCategoryEntry("xpcom-startup", MY_OBSERVER_NAME, true);aComponentManager.QueryInterface(CI.nsIComponentRegistrar);for (var key in this._objects) {var obj = this._objects[key];aComponentManager.unregisterFactoryLocation(obj.CID, aFileSpec);}}, getClassObject: function (aComponentManager, aCID, aIID) {if (!aIID.equals(CI.nsIFactory)) {throw CR.NS_ERROR_NOT_IMPLEMENTED;}for (var key in this._objects) {if (aCID.equals(this._objects[key].CID)) {return this._objects[key].factory;}}throw CR.NS_ERROR_NO_INTERFACE;}, canUnload: function (aComponentManager) {return true;}, _objects: {}};
  68. function NSGetModule(compMgr, fileSpec) {
  69.     for (var i in objects) {
  70.         gModule._objects[i] = new FactoryHolder(objects[i]);
  71.     }
  72.     return gModule;
  73. }
  74.